home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 88 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.1 KB  |  41 lines

  1. Path: ac.dal.ca!cook
  2. Newsgroups: comp.lang.c++
  3. Subject: Function template problem
  4. Message-ID: <1996Jan1.121642.44508@ac.dal.ca>
  5. From: cook@is.dal.ca (Adrian Ross Cook)
  6. Date: 1 Jan 96 12:16:41 -0400
  7. Nntp-Posting-Host: is.dal.ca
  8. X-Newsreader: TIN [version 1.2 PL2]
  9.  
  10. Hi there. Is it legal to use a template function as a member function of 
  11. a non-template class? If so, what is the proper syntax for doing this?
  12.  
  13. Currently I have something like the following:
  14.  
  15. class Blah{
  16.    ...other functions...
  17.    template <class Type>
  18.    Type foo(int index, Type aVal);
  19. };
  20.  
  21. and in my definitions file:
  22.  
  23. template <class Type>
  24. Type Blah::foo(int index, Type aVal)
  25. {
  26.  ...code...
  27. }
  28.  
  29. Anyway, my compiler (Turbo C++ for Windows 3.1) won't accept this. It 
  30. seems to be confusing my function template with a class template. 
  31. However, none of the C++ books I have say that you can't use a template 
  32. function as a class member function.
  33.  
  34. If anyone has encountered this kind of problem, I'd like to hear from 
  35. you. E-mail responses are preferred.
  36.  
  37. Thanks,
  38. Adrian Cook
  39. cook@ug.cs.dal.ca   cook@is.dal.ca
  40.  
  41.